Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expression: fix the behavior when adding date with big interval | tidb-test=pr/2260 #49228

Merged
merged 7 commits into from
Dec 12, 2023

Conversation

lcwangchao
Copy link
Collaborator

@lcwangchao lcwangchao commented Dec 6, 2023

What problem does this PR solve?

Issue Number: close #49227

What changed and how does it work?

  • date + interval X uint when X is a big value, we should get NULL
  • Fix some other interval cases to keep the same behavior with MySQL 8.0:
    • date + interval "true" DAY should not add one day, only date + interval true DAY should be seen as add 1 time unit.
    • date + interval "xxx1" uint, if an interval string does not start with +/- or a digit, it should be truncated as 0, not 1.
    • The unit SECOND is special, it should accept string in in exponential format, for example: select "1900-01-01 00:00:00" + INTERVAL "1e2" second; should add 100 seconds.
    • If the unit is SECOND , the interval string should be regarded as float, other units should be regarded as int.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

To make some behaviors same with Mysql8.0:

fix the behavior when adding date with big interval
interval with an invalid prefix will be seen as a zero value after this PR
interval with a string "true" will be seen as a zero value after this PR

@ti-chi-bot ti-chi-bot bot added needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 6, 2023
Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Merging #49228 (d914219) into master (e62699c) will increase coverage by 0.7537%.
Report is 20 commits behind head on master.
The diff coverage is 72.0720%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #49228        +/-   ##
================================================
+ Coverage   71.0591%   71.8128%   +0.7536%     
================================================
  Files          1368       1412        +44     
  Lines        401982     415363     +13381     
================================================
+ Hits         285645     298284     +12639     
- Misses        96472      98243      +1771     
+ Partials      19865      18836      -1029     
Flag Coverage Δ
integration 43.7218% <72.0720%> (?)
unit 71.0604% <ø> (+0.0013%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9663% <ø> (ø)
parser ∅ <ø> (∅)
br 47.7173% <ø> (-5.2442%) ⬇️

@lcwangchao lcwangchao force-pushed the date_add_bigv branch 3 times, most recently from 19e6df0 to 5bb3022 Compare December 6, 2023 14:34
@lcwangchao
Copy link
Collaborator Author

/retest

@lcwangchao lcwangchao changed the title expression: fix the behavior when adding date with big interval expression: fix the behavior when adding date with big interval | tidb-test=pr/2260 Dec 6, 2023
@lcwangchao
Copy link
Collaborator Author

/retest

@ti-chi-bot ti-chi-bot bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 7, 2023
pkg/expression/builtin_time.go Outdated Show resolved Hide resolved
@@ -2754,7 +2754,7 @@ type baseDateArithmetical struct {

func newDateArithmeticalUtil() baseDateArithmetical {
return baseDateArithmetical{
intervalRegexp: regexp.MustCompile(`-?[\d]+`),
intervalRegexp: regexp.MustCompile(`^[+-]?[\d]+`),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XXX1 should be parsed as "", not "1"

@lcwangchao lcwangchao force-pushed the date_add_bigv branch 3 times, most recently from 209f67b to d33c99a Compare December 7, 2023 06:13
@lcwangchao lcwangchao added compatibility-breaker Violation of forwards/backwards compatibility in a design-time piece. compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) and removed compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) labels Dec 7, 2023
@lcwangchao lcwangchao force-pushed the date_add_bigv branch 2 times, most recently from fa2a92f to e09eeb0 Compare December 7, 2023 09:46
Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

pkg/expression/builtin_time.go Outdated Show resolved Hide resolved
Copy link
Member

@YangKeao YangKeao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 7, 2023
@lcwangchao
Copy link
Collaborator Author

/retest

1 similar comment
@lcwangchao
Copy link
Collaborator Author

/retest

@lcwangchao
Copy link
Collaborator Author

/retest

@lcwangchao
Copy link
Collaborator Author

/retest

1 similar comment
@lcwangchao
Copy link
Collaborator Author

/retest

@lcwangchao
Copy link
Collaborator Author

/retest

Copy link
Contributor

@windtalker windtalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

ti-chi-bot bot commented Dec 12, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: windtalker, YangKeao

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added approved lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 12, 2023
Copy link

ti-chi-bot bot commented Dec 12, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-07 11:41:34.36265917 +0000 UTC m=+1700523.027885365: ☑️ agreed by YangKeao.
  • 2023-12-12 08:36:03.573809981 +0000 UTC m=+345254.611036893: ☑️ agreed by windtalker.

@lcwangchao lcwangchao removed needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. labels Dec 12, 2023
@ti-chi-bot ti-chi-bot bot merged commit 724b88b into pingcap:master Dec 12, 2023
15 of 16 checks passed
@lcwangchao lcwangchao deleted the date_add_bigv branch December 12, 2023 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved compatibility-breaker Violation of forwards/backwards compatibility in a design-time piece. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add date with a big intervals result incorrect values
3 participants